import { Injectable } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import * as fs from 'fs';
import * as path from 'path';
@Injectable()
export class TasksService {
  // 清除日志
  @Cron('* * 1 * *')
  clearLogs() {
    const logsDirectory = path.join(__dirname, '../../logs');
    fs.readdir(logsDirectory, (err, files) => {
      if (err) return;
      files.forEach((file) => {
        const filePath = path.join(logsDirectory, file);
        fs.unlink(filePath, (err) => {
          if (err) {
            console.error('Error deleting log file:', err);
            return;
          }
          console.log('Log file deleted:', file);
        });
      });
    });
  }
}
